package leetcode.code283.MoveZeroes;

/**
 * ˫ָ�룬��β��
 *
 * @author Administrator
 *
 */
public class Solution2 implements IMoveZeroes {

	@Override
	public void moveZeroes(int[] nums) {
		int len = nums.length;
		int numOfZeroes = nums[0] == 0 ? 1 : 0;
		for (int i = 1; i < len; i++) {
			if (nums[i] == 0) {
				numOfZeroes += 1;
			} else {
				if (numOfZeroes != 0) {// ��0����Ҫ�ƶ�
					nums[i - numOfZeroes] = nums[i];
					nums[i] = 0;// �м�����ν�����ñ�0
				}
			}
		}
	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug(new int[] { 0, 1, 0, 3, 12 });
		so.debug(new int[] { 2, 1 });
	}

//	����: [0,1,0,3,12]
//	���: [1,3,12,0,0]
	public void debug(int[] nums) {
		IMoveZeroes imz = new Solution2();
		imz.moveZeroes(nums);
		for (int num : nums) {
			System.out.print(num + ",");
		}
	}

}
